//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <ddkit.h>
#include <xllp_gpio.h>
#include <bulverde.h>

#define GPIORegVirtualBase  0x80E00000

//config GPIO port
void GpioSetup()
{
    // gpio pins init
    // the first entry is size

    static const XLLP_UINT32_T lowpins[] = {12, 81, 55, 51, 50, 52, 48, 17, 108, 53, 54, 85, 84/*, 79, 22*/};
//    static const XLLP_UINT32_T hipins[]  = {2, 83, 22};
    static const XLLP_UINT32_T inpins[]  = {9, 81, 55, 51, 50, 52, 48, 17, 108, 54};
    static const XLLP_UINT32_T outpins[] = {4, 53, 83, 45, 22};
    static const XLLP_UINT32_T altpins[] = {15, 81, 55, 51, 50, 52, 48, 17, 108, 53, 54, 85, 84, 83, 45, 22};
    static const XLLP_UINT32_T altfunc[] = {15,  2,  1,  1,  1,  1,  1,  2,   1,  2,  3,  3,  3,  0,  0,  0};
    // configure processor pins
    //      Mux         Pin         GPIO     Alt   Direction
    //  CIF_DD[0]:  P_CIF_DD0       81      alt2     in
    //  CIF_DD[1]:  P_CIF_DD1       55      alt1     in
    //  CIF_DD[2]:  P_CIF_DD2       51      alt1     in
    //  CIF_DD[3]:  P_CIF_DD3       50      alt1     in
    //  CIF_DD[4]:  P_CIF_DD4       52      alt1     in
    //  CIF_DD[5]:  P_CIF_DD5       48      alt1     in
    //  CIF_DD[6]:  P_CIF_DD6       17      alt2     in
    //  CIF_DD[7]:  P_CIF_DD7       108     alt1     in
    //  CIF_MCLK:   P_CIF_MCLK      53      alt2     out
    //  CIF_PCLK:   P_CIF_PCLK      54      alt3     in
    //  CIF_LV:     P_CIF_LV        85      alt3     in/out
    //  CIF_FV:     P_CIF_FV        84      alt3     in/out
    //  CAMERA_PWRWNB               83               out
    //  P_CAMERA_SHDN               45               out //
    //  P_CAMERA_RST                22               out

    P_XLLP_GPIO_T pGPIO = (P_XLLP_GPIO_T)GPIORegVirtualBase;;
    XllpGpioSetDirectionOut(pGPIO, (XLLP_UINT32_T*)outpins);
    XllpGpioSetDirectionIn (pGPIO, (XLLP_UINT32_T*)inpins);

//    XllpGpioSetOutputState1(pGPIO, (XLLP_UINT32_T*)hipins);
    XllpGpioSetOutput0(pGPIO, (XLLP_UINT32_T*)lowpins);
    XllpGpioSetAlternateFn (pGPIO, (XLLP_UINT32_T*)altpins, (XLLP_UINT32_T*)altfunc);

}

void GpioCloseCamera()
{
    // Need to do more ...
}
